using UnityEngine;
using System.Collections;

public class Item
{
	//默认2048 * 2048 够用，故就一张图片//
	private UIAtlas _atlas;
	private string _spriteName;
	private string _bgSpriteName;
	private byte _itemType;
	private int _itemID;
	private int _itemCount;
	private bool _visible;
	private bool _locked;
	private string _modelName;
	
	public Item (byte itemType, int itemID, int itemCount, bool visible)
	{
		_spriteName = itemType + "_" + itemID;
		//找到对应的品级// TODO
		if (itemType != 0) {
			_bgSpriteName = "1";
		} else {
			_bgSpriteName = "";
		}
		_itemType = itemType;
		_itemID = itemID;
		_itemCount = itemCount;
		_visible = visible;
		_locked = GameDefine.ITEMUNLOCKED;
	}
	
	//暂用//
	public Item (string spriteName, bool locked)
	{
		_spriteName = spriteName;
		_locked = locked;
	}
	
	public Item (string spriteName, bool visible, bool locked)
	{
		_bgSpriteName = "1";
		_spriteName = spriteName;
		_visible = visible;
		_locked = false;
	}
	
	public Item(string modelName){
		_modelName = modelName;
		string filePath = modelName + "/" + modelName + "_idle";
		_atlas = Resources.Load(filePath,typeof(UIAtlas)) as UIAtlas;
		_visible = true;
		_locked = false;
	}
	
	public UIAtlas Atlas {
		get {
			return _atlas;
		} 
		set {
			_atlas = value;
		}
	}
	
	public string SpriteName {
		get {
			return _spriteName;
		} 
		set {
			_spriteName = value;
		}
	}
	
	public string BgSpriteName {
		get {
			return _bgSpriteName;
		} 
		set {
			_bgSpriteName = value;
		}
	}
	
	public byte ItemType {
		get {
			return _itemType;
		}set {
			_itemType = value;
		}
	}
	
	public int ItemID {
		get {
			return _itemID;
		}
		set {
			_itemID = value;
		}
	}
	
	public int ItemCount {
		get {
			return _itemCount;
		}
		set {
			_itemCount = value;
		}
	}
	
	public bool Visible {
		get {
			return _visible;
		}
		set {
			_visible = value;
		}
	}
	
	public bool Locked {
		get {
			return _locked;
		}set {
			_locked = value;
		}
	}
	
	public string ModelName{
		get{
			return _modelName;
		}set{
			_modelName = value;
		}
	}
	
	public void Exchange (Item anotherItem)
	{
		UIAtlas tempAtlas = anotherItem.Atlas;
		anotherItem.Atlas = _atlas;
		_atlas = tempAtlas;
		
		string tempModelName = anotherItem.ModelName;
		anotherItem.ModelName = _modelName;
		_modelName = tempModelName;
		
		string tempSpriteName = anotherItem.SpriteName;
		string tempBgSpriteName = anotherItem.BgSpriteName;
		byte tempItemType = anotherItem.ItemType;
		int tempItemId = anotherItem.ItemID;
		int tempItemCount = anotherItem.ItemCount;
		bool tempVisible = anotherItem.Visible;
		
		anotherItem.SpriteName = _spriteName;
		anotherItem.BgSpriteName = _bgSpriteName;
		anotherItem.ItemType = _itemType;
		anotherItem.ItemID = _itemID;
		anotherItem.ItemCount = _itemCount;
		anotherItem.Visible = _visible;
		
		_spriteName = tempSpriteName;
		_bgSpriteName = tempBgSpriteName;
		_itemType = tempItemType;
		_itemID = tempItemId;
		_itemCount = tempItemCount;
		_visible = tempVisible;
	}
}
